/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GamePlay;

import FrameWork.IPlay;
import FrameWork.IState;
import FrameWork.Rectangle;
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author ThanhTri
 */
public class State_Start extends IState{
    Sprite m_SBack,m_SBT3,m_SBT4,m_SBT;
    Rectangle m_BPlay,m_BAbout,m_BHelp,m_BExit;
    int m_Index;
     public State_Start(IPlay _Play){
        super(_Play);
        m_IDState = Global.STATE_START ;
    }
    
    public void Init (){
        super.Init();
        try {
            m_SBack = new Sprite(Image.createImage("/image/menu.png"),
                                240, 320);
            m_SBT3 =new Sprite(Image.createImage("/image/bt3.png"),
                                56, 56);
            m_SBT4 = new Sprite(Image.createImage("/image/bt4.png"),
                                133, 86);
            m_SBT = new Sprite(Image.createImage("/image/bt5.png"),
                                240, 320);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        m_BPlay = new Rectangle(58, 113, 127, 80);
        m_BAbout = new Rectangle(20, 260, 50, 50);
        m_BHelp = new Rectangle(95, 260, 50, 50);
        m_BExit = new Rectangle(170, 260, 50, 50);
        m_Index = 0 ;
        
    }
    
    public void Update (float _Time){
        
    }
    public void PointerPressed(int x, int y){
       if(m_BPlay.Intersects(x, y))
           m_Play.setNextState(new State_PlayGame(m_Play));
       if(m_BAbout.Intersects(x, y))
           m_Play.setNextState(new State_About(m_Play));
       if(m_BHelp.Intersects(x, y))
           m_Play.setNextState(new State_Help(m_Play));
       if(m_BExit.Intersects(x, y)){
           m_Play.m_Main.destroyApp(false);
           m_Play.m_Main.notifyDestroyed();    
       }
    }
    public void KeyPressed (int _Keycode){
       if (_Keycode == -3 || _Keycode == 52){
            --m_Index;
            if(m_Index<0)m_Index=3;
        }
        //Right
        if (_Keycode == -4 || _Keycode == 54){
            m_Index= (m_Index+1)%4;
        }    
        if (_Keycode == -5 || _Keycode ==53){
            switch(m_Index){
                case 0:
                    m_Play.setNextState(new State_PlayGame(m_Play));
                    break;
                case 1:
                    m_Play.setNextState(new State_About(m_Play));
                    break;
                case 2:
                    m_Play.setNextState(new State_Help(m_Play));
                    break;
                case 3:
                    m_Play.m_Main.destroyApp(false);
                    m_Play.m_Main.notifyDestroyed();    
                    break;
            }            

        }

    }
    
    public void Render (){        
        super.Render();
        m_Graphics.setColor(200, 0, 0);
        m_Graphics.fillRect(0, 0, 240, 320);
        m_SBack.paint(m_Graphics);
        DrawButton(m_SBT3, m_SBT4, m_Index);
        m_SBT.paint(m_Graphics);
    }    
  
    public void Destroy (){

    }
    public void DrawButton (Sprite _SBT3,Sprite _SBT4,int _Index){
       if(_Index==0){
           _SBT4.setPosition(55, 110);
           _SBT4.paint(m_Graphics);
       };
       if(_Index==1){
           _SBT3.setPosition(17, 257);
           _SBT3.paint(m_Graphics);
       };
       if(_Index==2){
           _SBT3.setPosition(92, 257);
           _SBT3.paint(m_Graphics);
       };
       if(_Index==3){
           _SBT3.setPosition(167, 257);
           _SBT3.paint(m_Graphics);
       };
   }
}
